#include <iostream>
#include <string>
#include <pthread.h>
#include <unistd.h>

__thread int g_val = 100;

void* threadrun(void* args)
{
    std::string name = static_cast<const char*>(args);
    while(true)
    {
        std::cout << " name " << name << " tid is " << pthread_self() <<" g_val :" << g_val << " &g_val : " << &g_val << std::endl;
        g_val++;
        sleep(1);
    }

    return nullptr;
}

int main()
{
    pthread_t tid;
    pthread_create(&tid,nullptr,threadrun,(void*)"thread-1");
    while(true)
    {
        std::cout << "new thread " << tid << "g_val " << g_val << " &g_val : " << &g_val<<std::endl;
        sleep(1);
    }

    pthread_join(tid,nullptr);


    return 0;
}